package entities;

import java.awt.*;
import java.util.Map;

public class Shi extends BasePiece {
    public Shi(int x, int y, Color color) {
        super(x, y, color);
        if (color == BasePiece.RED_PIECE) {
            this.pieceName = "仕";
        } else {
            this.pieceName = "士";
        }

    }

    @Override
    public void updateAvailablePoints(Map<Point, BasePiece> pointPieceMap) {
        availablePoints.clear();
        int x = getPosition().x;
        int y = getPosition().y;

        /* 从当前位置斜上方一个点 */
//        if (x == 4 && y == 8){
//            BasePiece piece = pointPieceMap.get(new Point(x, y));
//            if ((piece == null)||(piece.getColor() != this.getColor())){
//                this.availablePoints.add(new AvailablePoint(x, y));
//            }
//        }
//        if (x == 3 && y == 7){
//            BasePiece piece = pointPieceMap.get(new Point(x, y));
//            if ((piece == null)||(piece.getColor() != this.getColor())){
//                this.availablePoints.add(new AvailablePoint(x, y));
//            }
//        }
        if ((x == 3 && y == 9) || (x == 3 && y == 7) || (x == 5 && y == 7) || (x == 5 && y == 9)) {
            BasePiece piece = pointPieceMap.get(new Point(4, 8));
            if ((piece == null) || (piece.getColor() != this.getColor())) {
                this.availablePoints.add(new AvailablePoint(4, 8));
            }
        }
        if (x == 4 && y == 8) {
            BasePiece piece1 = pointPieceMap.get(new Point(3, 7));
            if ((piece1 == null) || (piece1.getColor() != this.getColor())) {
                this.availablePoints.add(new AvailablePoint(3, 7));
            }
            BasePiece piece2 = pointPieceMap.get(new Point(3, 9));
            if ((piece2 == null) || (piece2.getColor() != this.getColor())) {
                this.availablePoints.add(new AvailablePoint(3, 9));
            }
            BasePiece piece3 = pointPieceMap.get(new Point(5, 7));
            if ((piece3 == null) || (piece3.getColor() != this.getColor())) {
                this.availablePoints.add(new AvailablePoint(5, 7));
            }
            BasePiece piece4 = pointPieceMap.get(new Point(5, 9));
            if ((piece4 == null) || (piece4.getColor() != this.getColor())) {
                this.availablePoints.add(new AvailablePoint(5, 9));
            }
        }
    }
}
